package com.oromwin.repos.server.response.media;

import java.io.DataOutputStream;
import java.io.IOException;

import org.apache.commons.logging.Log;

import com.oromwin.repos.common.Logger;
import com.oromwin.repos.common.ReposException;
import com.oromwin.repos.common.helper.IOHelper;
import com.oromwin.repos.data.MediaTable;
import com.oromwin.repos.server.response.NormalResponse;

public class InfoMediaResponse extends NormalResponse {
    private Log log = Logger.getLog(InfoMediaResponse.class);
    private MediaTable mediaTable = null;

    public InfoMediaResponse(boolean result, String description, MediaTable mTable) {
        Result = result;
        Description = description;
        mediaTable = mTable;
    }

    public void send(DataOutputStream dos) throws ReposException {
        try {
            dos.writeBoolean(Result);
            IOHelper.writeUTF8(dos, Description.toString());
            IOHelper.writeUTF8(dos, mediaTable.getVolumeId());
            IOHelper.writeUTF8(dos, mediaTable.getMediaId());
            IOHelper.writeUTF8(dos, mediaTable.getMediaPath().toString());
            dos.writeLong(mediaTable.getMediaMaxBytes());
            dos.writeLong(mediaTable.getMediaUsedBytes());
            dos.writeInt(mediaTable.getMediaFileCount());
            dos.writeBoolean(mediaTable.getMediaStatus());
            IOHelper.writeUTF8(dos, mediaTable.getMediaCreateDate());
            IOHelper.writeUTF8(dos, mediaTable.getMediaUpdateDate());
        } catch (IOException e) {
            throw ReposException.create(log, e);
        }
    }
}
